class Solution
{
public:
    array<int, 2> dxy[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    int n, m;
    bool st[55][55];
    int ans = 0;
    int dfs(vector<vector<int>> &g, int x, int y)
    {
        int num = 1;
        st[x][y] = true;
        for (auto [dx, dy] : dxy)
        {
            int xx = x + dx, yy = y + dy;
            if (xx >= 0 && xx < n && yy >= 0 && yy < m && g[xx][yy] && !st[xx][yy])
                num += dfs(g, xx, yy);
        }
        return num;
    }
    int maxAreaOfIsland(vector<vector<int>> &g)
    {
        if (g.empty())
            return 0;
        n = g.size(), m = g[0].size();
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                if (g[i][j])
                    ans = max(ans, dfs(g, i, j));
        return ans;
    }
};